<template>
    <div class="qingwu">
        <div class="admin_table_page_title">分账记录</div>
        <div class="unline underm"></div>

        <estate-search :searchConfig="searchConfig" @searchParams="search"></estate-search>

        <div class="admin_table_list">
            <a-table :columns="columns" :data-source="list" :pagination="false">

                <span slot="type" slot-scope="rows">
                    <div class="admin_goods_pic_txt">
                        <div v-if="rows.type == 1">电费</div>
                        <div v-if="rows.type == 2">水费</div>
                        <div v-if="rows.type == 3">物业费</div>
                    </div>
                </span>

                <span slot="status" slot-scope="rows">
                    <div class="admin_goods_pic_txt">
                        <div v-if="rows.status == 1"><a-tag>待审核</a-tag></div>
                        <div v-if="rows.status == 2"><a-tag color="green">通过</a-tag></div>
                        <div v-if="rows.status == 3"><a-tag color="red">未通过</a-tag></div>
                    </div>
                </span>


                <span slot="action" slot-scope="rows">
                    <div v-if="rows.status == 1">
                        <a-button @click="examine(2, rows.id)">通过</a-button>
                        <a-button type="danger" @click="examine(3, rows.id)">拒绝</a-button>
                    </div>
                </span>

            </a-table>

            <a-modal v-model="show" title="回执" @ok="handleOk" cancelText="取消" okText="确定">
                <a-form-model-item>
                    <a-input v-model="content" type="textarea"/>
                </a-form-model-item>
            </a-modal>

            <div class="admin_pagination" v-if="total>0">
                <a-pagination v-model="params.page" :page-size.sync="params.limit" :total="total" @change="onChange"
                              show-less-items/>
            </div>
        </div>
    </div>
</template>

<script>
    import estateSearch from '@/components/estate/search'

    export default {
        components: {estateSearch},
        props: {},
        data() {
            return {
                params: {
                    page: 1,
                    limit: 30,
                },
                show: false,
                status: null,
                id: null,
                content: '',
                total: 0, //总页数
                searchConfig: [
                    {label: '手机号', name: 'agent_mobile', type: 'text'},
                    {label: '姓名', name: 'agent_name', type: 'text'},
                ],
                selectedRowKeys: [], // 被选择的行
                columns: [
                    {title: '代理商姓名', dataIndex: 'electric_platform_agent.agent_mobile'},
                    {title: '代理商手机号', dataIndex: 'electric_platform_agent.agent_name'},
                    {title: '分账金额', dataIndex: 'money'},
                    {title: '充值订单', dataIndex: 'orderNo'},
                    {title: '状态', scopedSlots: {customRender: 'status'}},
                    {title: '费用类型', scopedSlots: {customRender: 'type'}},
                    {title: '分账时间', dataIndex: 'create_time'},
                    {title: '操作', scopedSlots: {customRender: 'action'}},
                ],
                list: []
            };
        },
        watch: {},
        computed: {},
        methods: {
            //审核
            examine(status, id) {
                this.status = status;
                this.id = id;
                this.show = true;
            },
            // 选择分页
            onChange(e) {
                this.params.page = e;
                this.onload();
            },
            handleOk() {
                this.$post(this.$api.electricAccountingRecordsStatus, {id: this.id, status: this.status, content: this.content}).then(res => {
                    this.show = false;
                    this.$message.success('成功');
                    this.onload();
                });
            },
            onload() {
                this.$get(this.$api.electricAccountingRecords, this.params).then(res => {
                    this.total = res.data.total;
                    this.list = res.data.data;
                });
            },
            // 重置
            reset() {
                location.reload();
            },
            // 搜索
            search(params) {
                let page = this.params.page;
                let per_page = this.params.limit;
                this.params = params;
                this.params.page = page;
                this.params.limit = per_page;
                this.onload();
            },
        },
        created() {
            this.onload();
        },
        mounted() {
        }
    };
</script>
<style lang="scss" scoped>

</style>
